<?php if(!defined('BASEPATH')) exit('No direct script access allowed');

class Users extends CI_Controller
{
    protected $sesja= null;
    protected $log  = null;
    protected $elems= null;
    
    public function __construct() 
    {
        parent::__construct();
        $this->load->model('Users_model','users');
        $this->sesja= $this->session->userdata('sesja');
        $this->log  = new Logevent();
        $this->elems= new Elements();
    }
    
    public function show_panel()
    {
        if(isset($this->sesja['id']))
        {
            $head['h1']     = 'Twój profil';
            $user   = $this->users->get_user($this->sesja['id']);
            if($user['stan'])
            {
                /*
                * 1 - zawodnik
                * 11 - trener
                */
                $cont['user']   = $user['wynik'];
                $cont['id']     = $this->sesja['id'];
                $this->load->model('League_model');
                $table          = $this->League_model->get_tables_by_user($this->sesja['id']);
                $cont['teams']  = ($table['wynik'] ? $table['wynik'] : '');
                switch($this->sesja['typ'])
                {
                    case 1:
                        $this->elems->load_view($this->sesja,'users/panel_player',$cont,$head);
                        break;
                    case 11:
                        $this->elems->load_view($this->sesja,'users/panel_coach',$cont,$head);
                        break;
                }
            }
            else
                $this->elems->load_alert($this->sesja,'error','Nie ma takiego użytkownika w systemie,');
        }
        else
            redirect('site/index');
    }
    
    public function is_editor($id)
    {
        $stan = $this->users->check_rights($id,'editor',1);
        $this->log->log_event($this->sesja,$stan);
        return $stan;
    }
}